package com.adam.test.service.impl;

import com.adam.test.entity.User1;
import com.adam.test.mapper.User1Mapper;
import com.adam.test.service.PropagationAddUser1Service;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author jiangwh
 */
@Service
public class PropagationAddUser1ServiceImpl implements PropagationAddUser1Service {
    
    @Resource
    private User1Mapper user1Mapper;

    @Override
    public void truncate() {
        user1Mapper.truncate();
    }

    @Override
    public void add(User1 bean) {
        user1Mapper.insert(bean);
    }

    @Override
    public void addThrow(User1 bean) {
        add(bean);
        // 模拟抛出异常，可以自定义异常，这里用个RuntimeException的子类异常，防止被其他RuntimeException的子类异常干扰，影响测试结果
        throw new IllegalStateException();
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void addRequired(User1 bean) {
        add(bean);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void addRequiredThrow(User1 bean) {
        addThrow(bean);
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void addRequiresNew(User1 bean) {
        add(bean);
    }

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    @Override
    public void addRequiresNewThrow(User1 bean) {
        addThrow(bean);
    }

    @Transactional(propagation = Propagation.NESTED)
    @Override
    public void addNested(User1 bean) {
        add(bean);
    }

    @Transactional(propagation = Propagation.NESTED)
    @Override
    public void addNestedThrow(User1 bean) {
        addThrow(bean);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public void addSupports(User1 bean) {
        add(bean);
    }

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public void addSupportsThrow(User1 bean) {
        addThrow(bean);
    }

    @Transactional(propagation = Propagation.MANDATORY)
    @Override
    public void addMandatory(User1 bean) {
        add(bean);
    }

    @Transactional(propagation = Propagation.MANDATORY)
    @Override
    public void addMandatoryThrow(User1 bean) {
        addThrow(bean);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    @Override
    public void addNotSupported(User1 bean) {
        add(bean);
    }

    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    @Override
    public void addNotSupportedThrow(User1 bean) {
        addThrow(bean);
    }

    @Transactional(propagation = Propagation.NEVER)
    @Override
    public void addNever(User1 bean) {
        add(bean);
    }

    @Transactional(propagation = Propagation.NEVER)
    @Override
    public void addNeverThrow(User1 bean) {
        addThrow(bean);
    }
    
}
